//
//  MXHomeSetFoodView.m
//  HNBaseProject
//
//  Created by xujie on 2024/6/1.
//

#import "MXHomeSetFoodView.h"

@implementation MXHomeSetFoodView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self createIU];
    }
    return self;
}

- (void)createIU {
    MJWeakSelf;
    //设置出粮
    self.setLab = [[UILabel alloc] init];
    self.setLab.userInteractionEnabled = YES;
    self.setLab.textAlignment = NSTextAlignmentCenter;
    self.setLab.text = @"设置出粮";
    self.setLab.backgroundColor = [UIColor colorWithHexString:@"#3378F7"];
    self.setLab.textColor = [UIColor whiteColor];
    self.setLab.font = PFRFont(12);
    self.setLab.layer.cornerRadius = 12.5;
    self.setLab.layer.masksToBounds = YES;
    [self addSubview:self.setLab];
    [self.setLab addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [weakSelf setOutFood];
    }]];
    [self.setLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(25);
        make.bottom.offset(0);
        make.left.offset(0);
        make.width.mas_equalTo(79);
    }];
    
    self.centerLine = [[UIView alloc] init];
    self.centerLine.backgroundColor = [UIColor dc_colorWithHexString:@"#000000" alpha:0.2];
    self.centerLine.layer.cornerRadius = 2;
    self.centerLine.layer.masksToBounds = YES;
    [self addSubview:self.centerLine];
    [self.centerLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(2);
        make.height.mas_equalTo(14);
        make.centerY.mas_equalTo(self.setLab);
        make.left.mas_equalTo(self.setLab.mas_right).offset(12);
    }];
    
    self.todayCountLab = [[UILabel alloc] init];
    [self addSubview:self.todayCountLab];
    self.todayCountLab.textColor = [UIColor dc_colorWithHexString:@"#000000" alpha:0.7];
    self.todayCountLab.font = PFRFont(12);
    NSString *countStr = @"0";
    NSString *titleStr = [NSString stringWithFormat:@"今日出粮 %@ 份",countStr];
    NSMutableAttributedString *attribut = [[NSMutableAttributedString alloc] initWithString:titleStr];
    [attribut addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:21 weight:UIFontWeightBold]} range:[titleStr rangeOfString:countStr]];
    self.todayCountLab.attributedText = attribut;
    [self.todayCountLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.setLab);
        make.left.mas_equalTo(self.centerLine.mas_right).offset(12);
    }];
    
}

-(void)reloadCount:(NSInteger)count{
    NSString *countStr = [NSString stringWithFormat:@"%ld",(long)count];
    NSString *titleStr = [NSString stringWithFormat:@"今日出粮 %@ 份",countStr];
    NSMutableAttributedString *attribut = [[NSMutableAttributedString alloc] initWithString:titleStr];
    [attribut addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:21 weight:UIFontWeightBold]} range:[titleStr rangeOfString:countStr]];
    self.todayCountLab.attributedText = attribut;
}

- (void)setOutFood {
    if (self.setClick) {
        self.setClick();
    }
}
@end
